package com.yanqu.road.server.cmd.activity.suoyao;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SuoYaoActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.suoyao.SuoYaoModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code= GameProtocol.S_SUOYAO_CHOOSE_BIG_REWARD,desc = "锁妖塔选择顶部大奖奖励")
public class SuoYaoChooseTopRewardCmd extends AbstractCommand {

    private int rewardId;

    private int index;

    private boolean isSelected; // 是否自选奖励

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SuoYaoActivityProto.SuoYaoChooseTopRewardReqMsg suoYaoChooseTaskRewardReqMsg = SuoYaoActivityProto.SuoYaoChooseTopRewardReqMsg.parseFrom(packet.getBytes());
        SuoYaoActivityProto.SuoYaoTopRewardMsg reward = suoYaoChooseTaskRewardReqMsg.getReward();
        rewardId = reward.getRewardId();
        index = reward.getIndex();
        isSelected = reward.getIsSelected();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SuoYaoModule.class).chooseTaskReward(rewardId, index, isSelected);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            SuoYaoActivityProto.SuoYaoChooseTopRewardRespMsg.Builder builder = SuoYaoActivityProto.SuoYaoChooseTopRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SUOYAO_CHOOSE_TASK_REWARD,builder);
        }
    }
}
